﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using KM.Models;

namespace KM.HtmlHelpers
{
    public static class RecordPager
    {
        public static MvcHtmlString RecordPage(this HtmlHelper html, PagingInfoModel pageInfo, Func<int, string> _url)
        {

            StringBuilder result = new StringBuilder();

            for (int i = 1; i <= pageInfo.TotalPages; i++)
            {
                TagBuilder builder = new TagBuilder("a");
                builder.MergeAttribute("href", _url(i));
                builder.InnerHtml = i.ToString();
                if (i == pageInfo.CurrentPage)
                    builder.AddCssClass("current");
                result.Append(builder.ToString());
            }

            return MvcHtmlString.Create(result.ToString());
        }
        public static MvcHtmlString PhanTrang(this HtmlHelper html, PagingInfoModel pageInfo, Func<int, string> _url)
        {
            StringBuilder result = new StringBuilder();
            TagBuilder builder;
            result.Append("<div class=\"dataTables_paginate paging_bootstrap\">");
            result.Append("<ul class=\"pagination\">");
            for (int i = 1; i <= pageInfo.TotalPages; i++)
            {
                builder = new TagBuilder("a");
                builder.MergeAttribute("href", _url(i));
                builder.InnerHtml = i.ToString();
                if (i == pageInfo.CurrentPage)
                {
                    result.Append("<li class=\"active\">" + builder.ToString() + "</li>");
                }
                else
                {
                    result.Append("<li >" + builder.ToString() + "</li>");
                }
            }
            result.Append("</ul>");
            result.Append("</div>");
            ////string result = "";

            //result = "<div class=\"dataTables_paginate paging_bootstrap\">";
            //result += "<ul class=\"pagination\">";
            //result += "<li class=\"prev disabled\"><a href=\"#\">← Previous</a></li>";
            //result += "<li class=\"active\"><a href=\"#\">1</a></li>";
            //result += "<li><a href=\"#\">2</a></li>";
            //result += "<li><a href=\"#\">3</a></li>";
            //result += "<li><a href=\"#\">4</a></li>";
            //result += "<li class=\"next\"><a href=\"#\">Next →</a></li>";
            //result += "</ul>";
            //result += "</div>";

            return MvcHtmlString.Create(result.ToString());
        }
    }
}